home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / zousan / src / graph.c next >
Text File  |  1994-06-01  |  4KB  |  199 lines

  1. /*
  2.  *   EGB graphics function     By N.Takahashi
  3.  *
  4.  *       ver0.1 1993/11/07
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10. #include <EGB.h>
  11. #include "GRAPH.H"
  12.  
  13. /* Global variable */
  14. char Egb[1536];
  15. char Para[64];
  16.  
  17.  
  18. /* 関数 : G_enlarge
  19.    mx,my = 画面の拡大率
  20.    tx,ty = 表示開始位置
  21.    sx,sy = 画面の大きさ
  22. */
  23. void G_enlarge( int mx, int my, int tx, int ty, int sx, int sy ) {
  24.     EGB_displayStart( Egb, 3, 0, 0 );
  25.     EGB_displayStart( Egb, 2, mx, my );
  26.     EGB_displayStart( Egb, 0, tx, ty );
  27.     EGB_displayStart( Egb, 1, 0, 0 );
  28.     EGB_displayStart( Egb, 3, sx, sy );
  29. }
  30.  
  31. /* 関数 : G_cls
  32.    引数なし
  33. */
  34. void G_cls( void ) {
  35.     EGB_clearScreen( Egb );
  36. }
  37.  
  38. /* 関数 : G_screen
  39.    smode = 画面のモ-ド (1 - 18)
  40.    page  = ペ-ジ (0,1)
  41. */
  42. void G_screen( int smode, int page ) {
  43.     EGB_resolution( Egb, page, smode );
  44.     EGB_writePage( Egb, page );
  45.     EGB_displayPage( Egb, 1, page+1 );
  46.     EGB_color( Egb, 0, 0x7fff );
  47.     EGB_color( Egb, 1, 0x8000 );
  48.     EGB_color( Egb, 2, 0 );
  49.     EGB_clearScreen( Egb );
  50. }
  51.  
  52. /* 関数 : G_active
  53.    page = ペ-ジ  (0,1)
  54.    disp = 表示ペ-ジ  (0 - 3)
  55.    pri  = プライオリティ  (0,1)
  56. */
  57. void G_active( int page, int disp, int pri ) {
  58.     EGB_writePage( Egb, page );
  59.     EGB_displayPage( Egb, pri, disp );
  60. }
  61.  
  62. /* 関数 : G_palette
  63.    color = 色 (0-15-255)
  64.    green,red,blue = 設定階調 (0 - 255)
  65.    vsync = vsyncを待つかどうか (0,1) 1:待つ
  66. */
  67. void G_palette( int color, int green, int red, int blue, int vsync ) {
  68.     DWORD( Para+0 )=1;
  69.     DWORD( Para+4 )=color;
  70.     BYTE( Para+8 )=blue;
  71.     BYTE( Para+9 )=red;
  72.     BYTE( Para+10 )=green;
  73.     BYTE( Para+11 )=0;
  74.     EGB_palette( Egb, vsync, Para );
  75. }
  76.  
  77. /* 関数 : G_put
  78.    x1,y1,x2,y2 = 座標
  79.    pbuf = パタ-ンバッファ
  80. */
  81. void G_put( int x1, int y1, int x2, int y2, void *pbuf ) {
  82. struct SREGS seg;
  83.     _segread( &seg );
  84.     DWORD( Para+0 )=(unsigned int)pbuf;
  85.     WORD( Para+4 )=seg.ds;
  86.     WORD( Para+6 )=x1;
  87.     WORD( Para+8 )=y1;
  88.     WORD( Para+10 )=x2;
  89.     WORD( Para+12 )=y2;
  90.     EGB_putBlock( Egb, 3, Para );
  91. }
  92.  
  93. /* 関数 : G_get
  94.    x1,y1,x2,y2 = 座標
  95.    pbuf = パタ-ンバッファ
  96. */
  97. void G_get( int x1, int y1, int x2, int y2, void *pbuf ) {
  98. struct SREGS seg;
  99.     _segread( &seg );
  100.     DWORD( Para+0 )=(unsigned int)pbuf;
  101.     WORD( Para+4 )=seg.ds;
  102.     WORD( Para+6 )=x1;
  103.     WORD( Para+8 )=y1;
  104.     WORD( Para+10 )=x2;
  105.     WORD( Para+12 )=y2;
  106.     EGB_getBlock( Egb, Para );
  107. }
  108.  
  109. /* 関数 : G_pset
  110.    x,y = 座標
  111.    color = 色 (0-15-255-32767 | 32768)
  112. */
  113. void G_pset( int x, int y, int color ) {
  114.     WORD( Para+0 )=1;
  115.     WORD( Para+2 )=x;
  116.     WORD( Para+4 )=y;
  117.     EGB_color( Egb, 0, color );
  118.     EGB_pset( Egb, Para );
  119. }
  120.  
  121. /* 関数 : G_color32k
  122.    green,red,blue = 設定階調 (0 - 255)
  123. */
  124. int G_color32k( int green, int red, int blue ) {
  125.     return( ((green<<7)&0x7c00)+((red<<2)&0x03e0)+((blue>>3)&0x001f) );
  126. }
  127.  
  128. /* 関数 : G_rectangle
  129.    x1,y1,x2,y2 = 座標
  130. */
  131. void G_rectangle( int x1, int y1, int x2, int y2 ) {
  132.     WORD( Para+0 )=x1;
  133.     WORD( Para+2 )=y1;
  134.     WORD( Para+4 )=x2;
  135.     WORD( Para+6 )=y2;
  136.     EGB_rectangle( Egb, Para );
  137. }
  138.  
  139. /* 関数 : G_dosterm
  140.    DOSコンソールに戻す。
  141. */
  142. void G_dosterm( void ) {
  143. int p0=4,p1=4,pr=1,dp=3,wp=0;
  144. char pal[]={ 16,0,0,0,
  145.             1,0,0,0, 0xb0,0,0, 0,
  146.             2,0,0,0, 0,0xb0,0, 0,
  147.             3,0,0,0, 0xb0,0xb0,0, 0,
  148.             4,0,0,0, 0,0,0xb0, 0,
  149.             5,0,0,0, 0xb0,0,0xb0, 0,
  150.             6,0,0,0, 0,0xb0,0xb0, 0,
  151.             7,0,0,0, 0xb0,0xb0,0xb0, 0,
  152.             8,0,0,0, 0x40,0x40,0x40, 0,
  153.             9,0,0,0, 0xf0,0,0, 0,
  154.             10,0,0,0, 0,0xf0,0, 0,
  155.             11,0,0,0, 0xf0,0xf0,0, 0,
  156.             12,0,0,0, 0,0,0xf0, 0,
  157.             13,0,0,0, 0xf0,0,0xf0, 0,
  158.             14,0,0,0, 0,0xf0,0xf0, 0,
  159.             15,0,0,0, 0xf0,0xf0,0xf0, 0,
  160.             0,0,0,0, 0,0,0, 0
  161.            };
  162.  
  163.     G_screen( p0, 0 );
  164.     EGB_palette( Egb, 1, pal );
  165.     G_screen( p1, 1 );
  166.     EGB_palette( Egb, 1, pal );
  167.     G_active( wp, dp, pr );
  168.     G_cls();
  169. }
  170.  
  171. /* 関数 : G_boxfull
  172.    x1,y1,x2,y2 = 座標
  173.    color = 色 (0-15-255-32767 | 32768)
  174. */
  175. void G_boxfull( int x1, int y1, int x2, int y2, int color ) {
  176.     EGB_color( Egb, 0, color );
  177.     EGB_color( Egb, 2, color );
  178.     EGB_paintMode( Egb, 0x22 );
  179.     WORD( Para+0 )=x1;
  180.     WORD( Para+2 )=y1;
  181.     WORD( Para+4 )=x2;
  182.     WORD( Para+6 )=y2;
  183.     EGB_rectangle( Egb, Para );
  184. }
  185.  
  186. /* 関数 : G_box
  187.    x1,y1,x2,y2 = 座標
  188.    color = 色 (0-15-255-32767 | 32768)
  189. */
  190. void G_box( int x1, int y1, int x2, int y2, int color ) {
  191.     EGB_color( Egb, 0, color );
  192.     EGB_paintMode( Egb, 0x02 );
  193.     WORD( Para+0 )=x1;
  194.     WORD( Para+2 )=y1;
  195.     WORD( Para+4 )=x2;
  196.     WORD( Para+6 )=y2;
  197.     EGB_rectangle( Egb, Para );
  198. }
  199.